package cn.elead.chaos.sso.server.web.monitor.controller;

import java.util.List;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import cn.elead.chaos.excel.ExcelUtil;

import cn.elead.chaos.core.enums.BusinessType;
import cn.elead.chaos.framework.monitor.operlog.Log;
import cn.elead.chaos.framework.web.global.response.UnifiedReturn;
import cn.elead.chaos.mybatils.web.controller.BaseController;
import cn.elead.chaos.mybatils.web.page.TableDataInfo;
import cn.elead.chaos.sso.server.web.monitor.domain.SysOperLog;
import cn.elead.chaos.sso.server.web.monitor.service.ISysOperLogService;

/**
 * 操作日志记录
 * 
 * @author ruoyi
 */
@Controller
@RequestMapping("/monitor/operlog")
public class SysOperlogController extends BaseController {
	
	private String prefix = "monitor/operlog";

	@Autowired
	private ISysOperLogService operLogService;

	@GetMapping
	@RequiresPermissions("monitor:operlog:view")
	public String operlog() {
		return prefix + "/operlog";
	}

	@ResponseBody
	@UnifiedReturn
	@PostMapping("/list")
	@RequiresPermissions("monitor:operlog:list")
	public TableDataInfo<SysOperLog> list(SysOperLog operLog) {
		startPage();
		List<SysOperLog> list = operLogService.selectOperLogList(operLog);
		return getDataTable(list);
	}

	@ResponseBody
	@PostMapping("/export")
	@RequiresPermissions("monitor:operlog:export")
	@Log(title = "操作日志", businessType = BusinessType.EXPORT)
	public String export(SysOperLog operLog) {
		List<SysOperLog> list = operLogService.selectOperLogList(operLog);
		ExcelUtil<SysOperLog> util = new ExcelUtil<SysOperLog>(SysOperLog.class);
		return util.exportExcel(list, "操作日志");
	}

	@ResponseBody
	@PostMapping("/remove")
	@RequiresPermissions("monitor:operlog:remove")
	public void remove(String ids) {
		operLogService.deleteOperLogByIds(ids);
	}

	@RequiresPermissions("monitor:operlog:detail")
	@GetMapping("/detail/{operId}")
	public String detail(@PathVariable("operId") Long operId, ModelMap mmap) {
		mmap.put("operLog", operLogService.selectOperLogById(operId));
		return prefix + "/detail";
	}

	@ResponseBody
	@PostMapping("/clean")
	@RequiresPermissions("monitor:operlog:remove")
	@Log(title = "操作日志", businessType = BusinessType.CLEAN)
	public void clean() {
		operLogService.cleanOperLog();
	}
}
